function join<T, P>(first: T, second: P) {
  return `${first}${second}`;
}
let j = join<number, string>(1, "2");
let j2 = join(3, "4");
console.log(j);

// 泛型中数组的使用
function myFun<T>(params: Array<T>) {
  return params;
}
let fn = myFun<string>(["123"]);
console.log(fn);

class SelectUser {
  constructor(private users: string[] | number[]) {}
  getUser(index: number): string | number {
    return this.users[index];
  }
}
const user = new SelectUser(["小刚", "小明", "小理"]);
console.log(user.getUser(1));

class SelectEmp<T> {
  constructor(private empList: T[]) {}
  getEmp(index: number): T {
    return this.empList[index];
  }
}
const emp = new SelectEmp<string>(["小刚1", "小明1", "小理1"]);
console.log(emp.getEmp(1));

interface Emp2 {
  name: string;
}
class SelectEmp2<T extends Emp2> {
  constructor(private empList: T[]) {}
  getEmp(index: number): string {
    return this.empList[index].name;
  }
}
const emp2 = new SelectEmp2([
  {
    name: "小刚2",
  },
  {
    name: "小明2",
  },
  {
    name: "小理2",
  },
]);
console.log(emp2.getEmp(1));

class SelectEmp3<T extends number | string> {
  constructor(private empList: T[]) {}
  getEmp(index: number): T {
    return this.empList[index];
  }
}
const emp3 = new SelectEmp3<string>(["小刚3", "小明3", "小理3"]);
console.log(emp3.getEmp(1));
